package com.zhixi.controller;

import com.alibaba.fastjson.JSONObject;
import com.zhixi.mapper.UserMapper;
import com.zhixi.pojo.User;
import com.zhixi.service.UserService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName UserController
 * @Author zhangzhixi
 * @Description
 * @Date 2022-5-1 12:15
 * @Version 1.0
 */
@RestController
@RequestMapping("/user")
public class UserController {

    // 日志
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService userService;

    @Autowired
    private RedisTemplate redisTemplate;


    /**
     * 通过ID查询用户
     *
     * @param id 用户ID
     * @return 用户信息
     */
    @RequestMapping("/getUserById/{id}")
    public User getUserById(@PathVariable("id") Long id) {
        // 查询数据库
        LOGGER.info("查询数据库");
        User selectById = userService.selectByIdUser(id);
        if (selectById != null) {
            return selectById;
        }
        return null;
    }
}

